<?php
defined('_JEXEC') or die('Restricted access');
class contentHelper
{
	function getAllData($star, $number, $ordering=NULL, $where=NULL)
	{
		if($where){
			$where = "state=1 AND $where";
		}else{
			$where = 'state=1';
		}
		
		if($ordering){
			$ordering= "ORDER BY $ordering";
		}else{
			$ordering='';
		}
		$sqlnum="select * from dm_content where $where";
		$sql="select * from dm_content where $where $ordering LIMIT $star, $number";
		$querynum=mysql_query($sqlnum);
		$number= mysql_num_rows($querynum);
		$query=mysql_query($sql);	
		
		$value=array();
		$value['query']=$query;
		$value['number']=$number;
		return  $value;
	}
	
	function getContent($id)
	{
		$sql="select c.*, cat.title AS cat_title, cat.alias AS cat_alias from dm_content AS c, dm_categories AS cat where c.catid=cat.id AND  c.id=$id";
		$rs=mysql_query($sql);
		$value=mysql_fetch_assoc($rs);
		return  $value;
	}
	
	function getCatid ($id)
	{
		$sql = "select catid from dm_content where id = $id";
		$rs = mysql_query($sql);
		$row = mysql_fetch_assoc($rs);
		$catid = $row['catid'];
		return $catid;
	}
}